package com.alibaba.citrus.cr.mn.order.center.facade.function.convert;

import com.alibaba.citrus.cr.b2b.trade.order.facade.common.SetOrderTag;
import com.alibaba.citrus.cr.common.enums.GeneralStatusEnum;
import com.alibaba.cz.base.tool.StringUtil;
import com.epoch.app.mnordercenter.model.dto.OrderLineBizQueryResponse;
import com.epoch.app.mnordercenter.model.dto.OrderLineSDO;

/**
 * @author zhoubc
 * @date 2023/5/26 15:53
 */
public class OrderLineSDOToOrderLineBizQueryResponseConvertor {

    public static OrderLineBizQueryResponse convert(OrderLineSDO orderLineSDO) {
        OrderLineBizQueryResponse orderLineBizQueryResponse = new OrderLineBizQueryResponse();
        orderLineBizQueryResponse.setId(orderLineSDO.getId());
        orderLineBizQueryResponse.setOrderId(orderLineSDO.getOrderId());
        orderLineBizQueryResponse.setOrderBizId(orderLineSDO.getOrderBizId());
        orderLineBizQueryResponse.setOuterOrderId(orderLineSDO.getOuterOrderId());
        orderLineBizQueryResponse.setOrderType(orderLineSDO.getOrderType());
        orderLineBizQueryResponse.setOrderTypeName(orderLineSDO.getOrderTypeName());
        orderLineBizQueryResponse.setOrderLineNo(orderLineSDO.getOrderLineNo());
        orderLineBizQueryResponse.setOuterOrderLineId(orderLineSDO.getOuterOrderLineId());
        orderLineBizQueryResponse.setOrderLineTag(orderLineSDO.getOrderLineTag());
        orderLineBizQueryResponse.setCustomerCode(orderLineSDO.getCustomerCode());
        orderLineBizQueryResponse.setCustomerName(orderLineSDO.getCustomerName());
        orderLineBizQueryResponse.setReceiveAddressCode(orderLineSDO.getReceiveAddressCode());
        orderLineBizQueryResponse.setReceiveDetailAddress(orderLineSDO.getReceiveDetailAddress());
        orderLineBizQueryResponse.setProductGroupName(orderLineSDO.getProductGroupName());
        orderLineBizQueryResponse.setProductGroupCode(orderLineSDO.getProductGroupCode());
        orderLineBizQueryResponse.setScItemId(orderLineSDO.getScItemId());
        orderLineBizQueryResponse.setScItemCode(orderLineSDO.getScItemCode());
        orderLineBizQueryResponse.setScItemTitle(orderLineSDO.getScItemTitle());
        orderLineBizQueryResponse.setSalesUnit(orderLineSDO.getSaleUnit());
        orderLineBizQueryResponse.setSalesUnitName(orderLineSDO.getSaleUnitName());
        orderLineBizQueryResponse.setInventoryUnit(orderLineSDO.getInventoryUnit());
        orderLineBizQueryResponse.setInventoryUnitName(orderLineSDO.getInventoryUnitName());
        orderLineBizQueryResponse.setUnitConvert(orderLineSDO.getUnitConvert());
        orderLineBizQueryResponse.setBisUnitCode(orderLineSDO.getBisUnitCode());
        orderLineBizQueryResponse.setBisUnitName(orderLineSDO.getBisUnitName());
        orderLineBizQueryResponse.setSalesOrganizationCode(orderLineSDO.getSalesOrganizationCode());
        orderLineBizQueryResponse.setSalesOrganizationName(orderLineSDO.getSalesOrganizationName());
        orderLineBizQueryResponse.setSalesChannelName(orderLineSDO.getSalesChannelName());
        orderLineBizQueryResponse.setSalesChannelCode(orderLineSDO.getSalesChannelCode());
        orderLineBizQueryResponse.setSalesDepartmentCode(orderLineSDO.getSalesDepartmentCode());
        orderLineBizQueryResponse.setSalesDepartmentName(orderLineSDO.getSalesDepartmentName());
        orderLineBizQueryResponse.setChannelCode(orderLineSDO.getChannelCode());
        orderLineBizQueryResponse.setChannelName(orderLineSDO.getChannelName());
        orderLineBizQueryResponse.setBusinessType(orderLineSDO.getBusinessType());
        orderLineBizQueryResponse.setBusinessTypeName(orderLineSDO.getBusinessTypeName());
        orderLineBizQueryResponse.setOrderStatus(orderLineSDO.getOrderStatus());
        orderLineBizQueryResponse.setOrderStatusDesc(orderLineSDO.getOrderStatusDesc());
        orderLineBizQueryResponse.setSubStatus(orderLineSDO.getSubStatus());
        orderLineBizQueryResponse.setSubStatusDesc(orderLineSDO.getSubStatusDesc());
        orderLineBizQueryResponse.setOrderQuantity(orderLineSDO.getOrderQuantity());
        orderLineBizQueryResponse.setUnitPrice(orderLineSDO.getUnitPrice());
        orderLineBizQueryResponse.setTotalAmount(orderLineSDO.getTotalAmount());
        orderLineBizQueryResponse.setActivityUnitPrice(orderLineSDO.getActivityUnitPrice());
        orderLineBizQueryResponse.setActivityTotalAmount(orderLineSDO.getActivityTotalAmount());
        orderLineBizQueryResponse.setDeliveryAmount(orderLineSDO.getDeliveryAmount());
        orderLineBizQueryResponse.setShippedAmount(orderLineSDO.getShippedAmount());
        orderLineBizQueryResponse.setFrontOrderId(orderLineSDO.getFrontOrderId());
        orderLineBizQueryResponse.setFrontOrderBizId(orderLineSDO.getFrontOrderBizId());
        orderLineBizQueryResponse.setForecastOrderType(orderLineSDO.getForecastOrderType());
        orderLineBizQueryResponse.setForecastOrderLineNo(orderLineSDO.getForecastOrderLineNo());
        orderLineBizQueryResponse.setForecastQuantity(orderLineSDO.getForecastQuantity());
        orderLineBizQueryResponse.setCreateReasonCode(orderLineSDO.getCreateReasonCode());
        orderLineBizQueryResponse.setCreateReasonName(orderLineSDO.getCreateReasonName());
        orderLineBizQueryResponse.setRefuseReasonCode(orderLineSDO.getRefuseReasonCode());
        orderLineBizQueryResponse.setRefuseReasonName(orderLineSDO.getRefuseReasonName());
        orderLineBizQueryResponse.setClosed(GeneralStatusEnum.descByCode(orderLineSDO.getClosed()));
        orderLineBizQueryResponse.setOrderRemark(orderLineSDO.getOrderRemark());
        orderLineBizQueryResponse.setOrderLineRemark(orderLineSDO.getOrderLineRemark());
        orderLineBizQueryResponse.setCustomerReferenceNo(orderLineSDO.getCustomerReferenceNo());
        orderLineBizQueryResponse.setCustomerPurchaseDate(orderLineSDO.getCustomerPurchaseDate());
        orderLineBizQueryResponse.setCustomerExpectDate(orderLineSDO.getCustomerExpectDate());
        orderLineBizQueryResponse.setActivityId(orderLineSDO.getActivityId());
        orderLineBizQueryResponse.setActivityLineNo(orderLineSDO.getActivityLineNo());
        orderLineBizQueryResponse.setActivityName(orderLineSDO.getActivityName());
        orderLineBizQueryResponse.setGiftFlag(orderLineSDO.getIsGift());
        orderLineBizQueryResponse.setManualPrice(orderLineSDO.getManualPrice());
        orderLineBizQueryResponse.setManualTotalAmount(orderLineSDO.getManualTotalAmount());
        orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getSAPFactoryCode());
        orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getSAPInventoryPoint());

        //1）	销售订单：展示明细行发货仓库
        //2）	退货订单：展示明细行收货仓库
        //3）	换货订单：退货行展示收货仓库,换货行展示发货仓库
        if(SetOrderTag.NORMAL.equals(orderLineSDO.getOrderLineTag())){
            orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getDeliveryStockCode());
            orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getDeliveryFactoryCode());
            orderLineBizQueryResponse.setWarehouseCode(orderLineSDO.getShippingWarehouseCode());
            orderLineBizQueryResponse.setWarehouseName(orderLineSDO.getShippingWarehouseName());
        }else if (SetOrderTag.RETURN.equals(orderLineSDO.getOrderLineTag())){
            orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getReceiveStockCode());
            orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getReceiveFactoryCode());
            orderLineBizQueryResponse.setWarehouseCode(orderLineSDO.getReceiveWarehouseCode());
            orderLineBizQueryResponse.setWarehouseName(orderLineSDO.getReceiveWarehouseName());
        }else if (SetOrderTag.EXCHANGE.equals(orderLineSDO.getOrderLineTag())){
            if(StringUtil.isNotEmpty(orderLineSDO.getReturnCharacter()) && "1".equals(orderLineSDO.getReturnCharacter())){
                orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getReceiveStockCode());
                orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getReceiveFactoryCode());
                orderLineBizQueryResponse.setWarehouseCode(orderLineSDO.getReceiveWarehouseCode());
                orderLineBizQueryResponse.setWarehouseName(orderLineSDO.getReceiveWarehouseName());
            }else{
                orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getDeliveryStockCode());
                orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getDeliveryFactoryCode());
                orderLineBizQueryResponse.setWarehouseCode(orderLineSDO.getShippingWarehouseCode());
                orderLineBizQueryResponse.setWarehouseName(orderLineSDO.getShippingWarehouseName());
            }
        }
        //兼容订单共享的字段
        if(StringUtil.isBlank(orderLineBizQueryResponse.getSAPInventoryPoint())){
            orderLineBizQueryResponse.setSAPInventoryPoint(orderLineSDO.getSAPInventoryPoint());
        }
        if(StringUtil.isBlank(orderLineBizQueryResponse.getSAPFactoryCode())){
            orderLineBizQueryResponse.setSAPFactoryCode(orderLineSDO.getSAPFactoryCode());
        }
        if(StringUtil.isBlank(orderLineBizQueryResponse.getWarehouseCode())){
            orderLineBizQueryResponse.setWarehouseCode(orderLineSDO.getWarehouseCode());
        }
        if(StringUtil.isBlank(orderLineBizQueryResponse.getWarehouseName())){
            orderLineBizQueryResponse.setWarehouseName(orderLineSDO.getWarehouseName());
        }

        orderLineBizQueryResponse.setShippingWarehouseCode(orderLineSDO.getShippingWarehouseCode());
        orderLineBizQueryResponse.setShippingWarehouseName(orderLineSDO.getShippingWarehouseName());
        orderLineBizQueryResponse.setReceiveWarehouseCode(orderLineSDO.getReceiveWarehouseCode());
        orderLineBizQueryResponse.setReceiveWarehouseName(orderLineSDO.getReceiveWarehouseCode());
        orderLineBizQueryResponse.setProducteDate(orderLineSDO.getProducteDate());
        orderLineBizQueryResponse.setDeliveryMethod(orderLineSDO.getDeliveryMethod());
        orderLineBizQueryResponse.setDeliveryMethodName(orderLineSDO.getDeliveryMethodName());
        orderLineBizQueryResponse.setCreatorId(orderLineSDO.getCreatorId());
        orderLineBizQueryResponse.setCreatorName(orderLineSDO.getCreatorName());
        orderLineBizQueryResponse.setCreatorWorkId(orderLineSDO.getCreatorWorkId());
        orderLineBizQueryResponse.setUpdatorId(orderLineSDO.getUpdatorId());
        orderLineBizQueryResponse.setUpdatorName(orderLineSDO.getUpdatorName());
        orderLineBizQueryResponse.setUpdatorWorkId(orderLineSDO.getUpdatorWorkId());
        orderLineBizQueryResponse.setGmtCreateDate(orderLineSDO.getGmtCreateDate());
        orderLineBizQueryResponse.setGmtModifiedDate(orderLineSDO.getGmtModifiedDate());
        orderLineBizQueryResponse.setSyncVersion(orderLineSDO.getSyncVersion());
        orderLineBizQueryResponse.setFromSys(orderLineSDO.getFromSys());
        orderLineBizQueryResponse.setSourceOrderNo(orderLineSDO.getSourceOrderNo());
        orderLineBizQueryResponse.setSourceLineNum(orderLineSDO.getSourceLineNum());
        return orderLineBizQueryResponse;
    }

}
